package indi.zhifa.recipe.bailan.framework.mysql.entity.po;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class SysBaseEntity {
    @Schema(title = "主键")
    @TableId(type = IdType.ASSIGN_ID)
    protected Long id;
    @JSONField(serialize = false, deserialize = false)
    @TableField(fill = FieldFill.INSERT)
    @Schema(title = "创建时间")
    protected LocalDateTime createTime;
    @JSONField(serialize = false, deserialize = false)
    @TableField(fill = FieldFill.UPDATE)
    @Schema(title = "修改时间")
    protected LocalDateTime modifyTime;
    @Schema(title = "版本")
    @Version
    protected Integer version;

    public void createInit() {
        id = IdWorker.getId();
        // 靠全局配置填充
        createTime = null;
        modifyTime = null;
        version = 0;
    }

    public void updateInit() {
        modifyTime = null;
    }
}
